import {transformTime} from '../../utils';
import {useCallback} from 'react';

export default (departDate, dispatch, prevDate, nextDate) => {
  const isPrevDisabled = transformTime(departDate) <= transformTime();
  const isNextDisabled = transformTime(departDate) - transformTime() > 20 * 86400 * 1000;

  const prev = useCallback(() => {
    if (isPrevDisabled) {
      return;
    }
    dispatch(prevDate());
  }, [isPrevDisabled]);

  const next = useCallback(() => {
    if (isNextDisabled) {
      return;
    }
    dispatch(nextDate());
  }, [isNextDisabled]);

  return {
    prev,
    isPrevDisabled,
    next,
    isNextDisabled,
  }
}
